import { AntDesignOutlined, CrownOutlined, SmileOutlined, TabletOutlined } from '@ant-design/icons';
import { ProSettings } from '@ant-design/pro-layout';
import { LikeOutlined, UserOutlined } from '@ant-design/icons';
import ProLayout, { PageContainer, SettingDrawer } from '@ant-design/pro-layout';
import { Avatar, Button, Descriptions, Result, Space, Statistic } from 'antd';
import React, { useState } from 'react';
import { Link, useRouteMatch } from 'umi';
import defaultProps from './_defaultProps';
import pubSub from 'pubsub-js'
import lodash from 'lodash'
import RegExpUtil from '../utils/RegExpUtil'

export default (props) => {
    const [settings, setSetting] = useState();
    const [pathname, setPathname] = useState('/welcome');
    const [showTag, setShowTag] = useState(true);
    const match = useRouteMatch();
    console.log("进来了什么", props, settings)
    console.log("获得了什么匹配消息", props.location)

    pubSub.unsubscribe("layoutPro")
    pubSub.subscribe("layoutPro", (title, data) => {
        setShowTag(data.showTag)
    })
    if (RegExpUtil.checkHome(props.location.pathname) && showTag) {
        setShowTag(false)
    }

    // lodash.forEach(defaultProps.route.routes, function (value, key) {
    //     console.log("自动化 ", value.path)
    //     if (value.path == "/home") {
    //         setShowTag(false)
    //         return
    //     }
    // });



    return (
        <div
            id="test-pro-layout"
            style={{
                height: '100vh',
            }}
        >
            <ProLayout
                pure={showTag}
                {...defaultProps}
                location={{
                    pathname,
                }}
                waterMarkProps={{
                    content: 'Pro Layout',
                }}
                menuFooterRender={(props) => {
                    return (
                        <a
                            style={{
                                lineHeight: '48rpx',
                                display: 'flex',
                                height: 48,
                                color: 'rgba(255, 255, 255, 0.65)',
                                alignItems: 'center',
                            }}
                            href="https://preview.pro.ant.design/dashboard/analysis"
                            target="_blank"
                            rel="noreferrer"
                        >
                            <img
                                alt="pro-logo"
                                src="https://procomponents.ant.design/favicon.ico"
                                style={{
                                    width: 16,
                                    height: 16,
                                    margin: '0 16px',
                                    marginRight: 10,
                                }}
                            />
                            {!props?.collapsed && 'Preview Pro'}
                        </a>
                    );
                }}
                onMenuHeaderClick={(e) => console.log(e)}
                menuItemRender={(item, dom) => (
                    // <a
                    //     onClick={() => {
                    //         setPathname(item.path || '/welcome');
                    //         console.log("打开什么", item)
                    //     }}
                    // >
                    //     {dom}
                    // </a>
                    <Link to={item.path ?? '/'} onClick={() => {
                        setPathname(item.path || '/welcome');
                        console.log("打开什么", item, dom)
                    }}>
                        {dom}
                    </Link>
                )}
                rightContentRender={() => (
                    <div>
                        <Avatar shape="square" size="small" icon={<UserOutlined />} />
                    </div>
                )}
                {...settings}
            >
                <div
                    style={{
                        height: '120vh',
                    }}
                >
                    {props.children}
                </div>
            </ProLayout>
        </div >
    );
};